package com.haois.mp.database.module.common.daomain;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * description
 *
 * @author RuiHaoZ on GuangZhou
 * @date 2018/9/4 22:57
 */
public class JsonFor {

    public static List<Peccancy> pecTransfer(JSONObject jsonObject) {
        List<Peccancy> peccancies = new ArrayList<>();
        jsonObject = JSONObject.fromObject(jsonObject.get("result"));
        String province = jsonObject.getString("province");
        String city = jsonObject.getString("city");
        String hphm = jsonObject.getString("hphm");
        String hpzl = jsonObject.getString("hpzl");
        JSONArray jsonArray = jsonObject.getJSONArray("lists");
        if (!jsonArray.isEmpty()) {
            for (int i = 0; i < jsonArray.size(); i++) {
                Peccancy peccancy = new Peccancy(province, city, hphm, hpzl);
                JSONObject jb = jsonArray.getJSONObject(i);

                peccancy.setDate(jb.getString("date"));
                peccancy.setArea(jb.getString("area"));
                peccancy.setAct(jb.getString("act"));
                peccancy.setCode(jb.getString("code"));
                peccancy.setFen(jb.getInt("fen"));
                peccancy.setWzcity(jb.getString("wzcity"));
                peccancy.setMoney(jb.getInt("money"));
                peccancy.setHandled(jb.getString("handled"));
                peccancy.setArchiveno(jb.getString("archiveno"));

                peccancies.add(peccancy);
            }
        }
        return peccancies;
    }

    public static Driver driverTransfer(String result) {
        Driver driver = new Driver();
        JSONObject jsonObject = JSONObject.fromObject(result);
        String status = jsonObject.getString("status");
        String msg = jsonObject.getString("msg");
        driver.setCode(status);
        if (!"0".equals(status)) {
            driver.setCode(status + ":" + msg);
            return driver;
        } else {
            driver.setCode("0");
        }
        jsonObject = JSONObject.fromObject(jsonObject.get("result"));

        driver.setScore(jsonObject.getInt("score"));
        driver.setLicenseNo(jsonObject.getString("licensenumber"));
        try {
            driver.setName(jsonObject.getString("realname"));
            driver.setClassModel(jsonObject.getString("type"));
            driver.setDossier(jsonObject.getString("licenseid"));
            driver.setStartDate(jsonObject.getString("startdate"));
            driver.setEndDate(jsonObject.getString("enddate"));
            driver.setStatus(jsonObject.getString("licensestatus"));
        } catch (Exception e) {

        }
        return driver;
    }
}
